/* Note: 	firm_reg_main_final runs regressions with interactions.
			
*  Input: 	firm_reg_final. dta 
			
*  Tables:  Table 9, 10, 11, 12, B.11 
			
*/

clear all
grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1

* Set up control variables
local controls TotalAssetsLog_PRE FCLRatio_PRE Deriv_PRE  
 
 
********************************************************************************
*	PART I. High Hedge dummy
********************************************************************************
use "./Data/firm_reg_final", clear


label var highHR_PRE "High Hedge"
local controls TotalAssetsLog_PRE FCLRatio_PRE Deriv_PRE 

drop if PDisc==1
keep if fxdseller_PRE==1
drop if Export_A==.
summ Exposure_std
 
*exporters only

local i=101
foreach var in "TotalNotionalNetA" "ExpKRW09Log" "DomLog" {
drop if Export_A==.
quietly reg d`var' c.Exposure_std##i.highHR_PRE  if Year==2010 &  fxdseller_PRE==1, vce(cluster firm)
eststo m`i'
estadd local FC "N"
local i=`i'+1

reg d`var' c.Exposure_std##i.highHR_PRE `controls' i.Industry1 if Year==2010 & fxdseller_PRE==1, vce(cluster firm)

eststo m`i'
estadd local FC "Y"
local i=`i'+1
}

esttab m101 m102 m103 m104 m105 m106, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std)


///// PREVIEW TABLE 9(a):
esttab m103 m104, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogExport" "LogExport") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace

///// PREVIEW TABLE 10:
esttab m101 m102, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("FXD/Asset" "FXD/Asset") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace

///// PREVIEW TABLE 11:
esttab m105 m106, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogDomesticSales" "LogDomesticSales") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace



///// EXPORT TABLE 9(a), 10, 11 ////////////////////////////////////////////////

local fn="./Output/Table_9a_firm_lvl_exports_v10_v4.tex"

esttab m103 m104 using `fn', s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogExport" "LogExport") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace


local fn="./Output/Table_10_firm_lvl_pos_v10_v4.tex"

esttab m101 m102 using `fn', s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("FXD/Asset" "FXD/Asset") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace


local fn="./Output/Table_11_firm_lvl_domsales_v10_v4.tex"

esttab m105 m106 using `fn', s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogDomesticSales" "LogDomesticSales") label ///
keep(Exposure_std 1.highHR_PRE 1.highHR_PRE#c.Exposure_std _cons) order(1.highHR_PRE#c.Exposure_std) replace
 


********************************************************************************
*	PART II. Cash Triple Diff (Table 12)
******************************************************************************** 

local i=101
foreach var in "ExpLog" "ExpShare"{
drop if Export_A==.
reg d`var' c.Exposure_std##i.highHR_PRE##c.Cash_bal_A_ts_PRE  if Year==2010 &  fxdseller_PRE==1, vce(cluster firm)
eststo m`i'
estadd local FC "N"
local i=`i'+1

reg d`var' c.Exposure_std##i.highHR_PRE##c.Cash_bal_A_ts_PRE `controls' i.Industry1 if Year==2010 & fxdseller_PRE==1, vce(cluster firm)

eststo m`i'
estadd local FC "Y"
local i=`i'+1
}

esttab m101 m102 m103 m104, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
label ///
keep(Exposure_std 1.highHR_PRE Cash_bal_A_ts_PRE  ///
	1.highHR_PRE#c.Exposure_std c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Cash_bal_A_ts_PRE ///
	1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE _cons) /// 
	order(1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Exposure_std 1.highHR_PRE#c.Cash_bal_A_ts_PRE c.Exposure_std#c.Cash_bal_A_ts_PRE) 

esttab m102 m104, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
label ///
keep(Exposure_std 1.highHR_PRE Cash_bal_A_ts_PRE  ///
	1.highHR_PRE#c.Exposure_std c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Cash_bal_A_ts_PRE ///
	1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE _cons) /// 
	order(1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Exposure_std 1.highHR_PRE#c.Cash_bal_A_ts_PRE c.Exposure_std#c.Cash_bal_A_ts_PRE) mtitle("LogExport" "ExpShare") replace 

 
///// EXPORT TABLE 12 //////////////////////////////////////////////////////	
label var highHR_PRE "High Hedge"
label var Exposure_std "Exposure"
label var Cash_bal_A_ts_PRE "Cash"
 
local fn="./Output/Table_12_firm_lvl_ddd_v10_v4.tex"
esttab m102 m104 using `fn', s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
label ///
keep(Exposure_std 1.highHR_PRE Cash_bal_A_ts_PRE  ///
	1.highHR_PRE#c.Exposure_std c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Cash_bal_A_ts_PRE ///
	1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE _cons) /// 
	order(1.highHR_PRE#c.Exposure_std#c.Cash_bal_A_ts_PRE 1.highHR_PRE#c.Exposure_std 1.highHR_PRE#c.Cash_bal_A_ts_PRE c.Exposure_std#c.Cash_bal_A_ts_PRE) mtitle("LogExport" "ExpShare") replace 
	
*-------------------------------------------------------------------------------
 

 
********************************************************************************
*	PART II. Export hedge ratio continous
********************************************************************************
use "./Data/firm_reg_final", clear
label var highHR_PRE "High Hedge"

local controls TotalAssetsLog_PRE FCLRatio_PRE Deriv_PRE  

summarize Export_hedge_PRE if Year==2009

g Export_hedge_PRE_std= (Export_hedge_PRE -`r(mean)' )/`r(sd)'
label var Export_hedge_PRE_std "Export Hedge Ratio"

drop if PDisc==1

label var Exposed "Exposed"
label var Exposure_std "Exposure"
label var Export_hedge_PRE "Export HedgeRatio"
label var FCL_hedge_PRE "FCL HedgeRatio"
label var highHR_PRE "HighHedge"


drop if Export_A==.  
keep if Year==2010 & fxdseller_PRE==1


local i=111

local controls TotalAssetsLog_PRE FCLRatio_PRE Deriv_PRE  


foreach var in "ExpKRW09Log" {
drop if Export_A==.
reg d`var' c.Exposure_std##c.Export_hedge_PRE_std if Year==2010 & fxdseller_PRE==1, vce(cluster firm)
eststo m`i'
estadd local FC "N"
local i=`i'+1

reg d`var' c.Exposure_std##c.Export_hedge_PRE_std `controls' i.Industry1 if Year==2010 & fxdseller_PRE==1 & Export_A~=., vce(cluster firm)

eststo m`i'
estadd local FC "Y"
local i=`i'+1
}
 

///// PREVIEW TABLE 9(b):
esttab m111 m112, s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogExport" "LogExport") label ///
keep(Exposure_std Export_hedge_PRE_std c.Exposure_std#c.Export_hedge_PRE_std _cons) order(c.Exposure_std#c.Export_hedge_PRE_std) replace



 
///// EXPORT NEW TABLE 9(B) ////////////////////////////////////////////////////
local fn="./Output/Table_9b_firm_lvl_exports_cont_v10_v4.tex"
esttab m111 m112 using `fn', s(FC N r2, /// 
label("FirmControls" "N" "RSqr")) star(* 0.1 ** 0.05 *** 0.01 ) ///
mtitle("LogExport" "LogExport") label ///
keep(Exposure_std Export_hedge_PRE_std c.Exposure_std#c.Export_hedge_PRE_std _cons) order(c.Exposure_std#c.Export_hedge_PRE_std) replace
 
*-------------------------------------------------------------------------------

